<?php

namespace App\Inventor\Controllers;

use App\Services\TransverseService;
use App\Transverse;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;

class TransverseController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '横向课题';
    protected $service;

    public function __construct(TransverseService $service)
    {
        $this->service = $service;
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Transverse());
        $grid->model()->where('user_id',Admin::user()->id);
        $this->service->gridColumn($grid,0);
        $grid->batchActions(function(Grid\Tools\BatchActions $actions){
            $actions->disableDeleteAndHodeSelectAll();
        });
        return $grid;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Transverse());
        $this->service->form($form);
        return $form;
    }
}
